package com.zhentao.service.impl;

import com.zhentao.mapper.DeptMapper;
import com.zhentao.pojo.Dept;
import com.zhentao.service.DeptService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

/**
 * @Date 2024/4/10 14:45
 * @Author xdm
 **/
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Autowired
    private RestTemplate restTemplate;

    @GlobalTransactional
    //@Transactional
    @Override
    public Integer add(Dept dept) {
        System.out.println(dept+"1");
        deptMapper.insert(dept);

        System.out.println(dept+"2");

        //这个服务里面调用producer的add方法
        String path="http://producer/dept/add";
        restTemplate.postForEntity(path, dept,String.class);

        int i=1/0;

        return 1;
    }
}
